package com.example.springboot.mapper;

import com.example.springboot.entity.Base;
import com.example.springboot.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BaseMapper {
@Select("select * from base inner join touch on base.id = touch.baseId where finished = '否' and name like concat('%' ,#{name},'%')  limit #{pageNum},#{pageSize}")

    List<Base> selectPage(Integer pageNum, Integer pageSize, String name);
    @Select("select count(*) from base inner join touch on base.id = touch.baseId where finished = '否' and name like concat('%' ,#{name},'%')")
    Integer selectTotal(String name);
//    @Insert("INSERT into user(username,password,phone,unit,name) VALUES (#{username},#{password},#{phone},#{unit},#{name})")
//    int insert(User user);
    @Insert("INSERT into base(idCard,name,age,gender,address,phone) VALUES (#{idCard},#{name},#{age},#{gender},#{address},#{phone})")
    int insert(Base base);
    @Insert("INSERT into touch(comeFrom,isoAddress,startDate,finished) VALUES (#{comeFrom},#{isoAddress},#{startDate},#{finished})")
    int insert1(Base base);
    @Insert("Insert into inspect(baseId,testDate,ctTest,nuTest) VALUES(#{baseId}, #{testDate},#{ctTest},#{nuTest})")
    int inserths(Base base);
    @Update("Update touch set finished = '是' where baseId=#{baseId} ")
    int update(Base base);
@Insert("Insert into cure (baseId,dischargeDate,current) VALUES (#{baseId},#{dischargeDate},#{current})")
int insertzy(Base base);
    @Insert("Insert into dead (baseId,deadTime) VALUES (#{baseId},#{deadTime})")
    int insertsw(Base base);
    @Select("select * from patient inner join base on patient.baseId=base.id where patient.baseId not IN (select baseId from cure) and patient.baseId NOT IN (select baseId from dead) and name like concat('%' ,#{name},'%')  limit #{pageNum},#{pageSize}")
    List<Base> selectqzpg(Integer pageNum,Integer pageSize,String name);
    @Select("select count(*) from patient inner join base on patient.baseId=base.id where patient.baseId not IN (select baseId from cure) and patient.baseId NOT IN (select baseId from dead) and name like concat('%' ,#{name},'%')")
    Integer selectqzTotal(String name);
    @Update("Update patient set infectionSource=#{infectionSource},onsetDate=#{onsetDate},symptoms=#{symptoms},critical=#{critical},hospital=#{hospital},note=#{note} where baseId=#{baseId}")
    int updatezl(Base base);
  @Select("select * from inspect where baseId=#{baseId}")
    List<Base> cxhs(String baseId);
  @Select("select * from base JOIN dead ON base.id = dead.baseId JOIN patient on base.id = patient.baseId and name like concat('%' ,#{name},'%')  limit #{pageNum},#{pageSize}")
    List<Base> cxsw(Integer pageNum,Integer pageSize,String name);
    @Select("select count(*) from base JOIN dead ON base.id = dead.baseId JOIN patient on base.id = patient.baseId and name like concat('%' ,#{name},'%')")
    Integer cxswTotal(String name);
    @Select("select * from base JOIN cure ON base.id = cure.baseId JOIN patient on base.id = patient.baseId and name like concat('%' ,#{name},'%')  limit #{pageNum},#{pageSize}")
    List<Base> cxzy(Integer pageNum,Integer pageSize,String name);
    @Select("select count(*) from base JOIN cure ON base.id = cure.baseId JOIN patient on base.id = patient.baseId and name like concat('%' ,#{name},'%')")
    Integer cxzyTotal(String name);
}
